{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "066e0563",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import TreeMap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "eff2ecdd",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "data = [\n",
    "    {'value': 40, 'name': '伯伯'},\n",
    "    {\n",
    "        'value': 180,\n",
    "        'name': '父亲',\n",
    "        'children': [\n",
    "            {'value': 76, \n",
    "             'name': '我',\n",
    "             'children': [\n",
    "                 {'value': 12, 'name': '大儿子'},\n",
    "                 {'value': 28, 'name': '二儿子'},\n",
    "                 {'value': 20, 'name': '三女儿'},\n",
    "                 {'value': 16, 'name': '四女儿'},\n",
    "             ]\n",
    "            },\n",
    "        ]\n",
    "    }\n",
    "    \n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f5341f3c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"00a25352294843e68193c55b0de4b34a\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_00a25352294843e68193c55b0de4b34a = echarts.init(\n",
       "                    document.getElementById('00a25352294843e68193c55b0de4b34a'), 'white', {renderer: 'canvas'});\n",
       "                var option_00a25352294843e68193c55b0de4b34a = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"treemap\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"value\": 40,\n",
       "                    \"name\": \"\\u4f2f\\u4f2f\"\n",
       "                },\n",
       "                {\n",
       "                    \"value\": 180,\n",
       "                    \"name\": \"\\u7236\\u4eb2\",\n",
       "                    \"children\": [\n",
       "                        {\n",
       "                            \"value\": 76,\n",
       "                            \"name\": \"\\u6211\",\n",
       "                            \"children\": [\n",
       "                                {\n",
       "                                    \"value\": 12,\n",
       "                                    \"name\": \"\\u5927\\u513f\\u5b50\"\n",
       "                                },\n",
       "                                {\n",
       "                                    \"value\": 28,\n",
       "                                    \"name\": \"\\u4e8c\\u513f\\u5b50\"\n",
       "                                },\n",
       "                                {\n",
       "                                    \"value\": 20,\n",
       "                                    \"name\": \"\\u4e09\\u5973\\u513f\"\n",
       "                                },\n",
       "                                {\n",
       "                                    \"value\": 16,\n",
       "                                    \"name\": \"\\u56db\\u5973\\u513f\"\n",
       "                                }\n",
       "                            ]\n",
       "                        }\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"width\": \"80%\",\n",
       "            \"height\": \"80%\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"inside\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"upperlabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"inside\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"drillDownIcon\": \"\\u25b6\",\n",
       "            \"roam\": true,\n",
       "            \"nodeClick\": \"zoomToNode\",\n",
       "            \"zoomToNodeRatio\": 0.1024,\n",
       "            \"colorMappingBy\": \"index\",\n",
       "            \"visibleMin\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u77e9\\u5f62\\u6811\\u56fe\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_00a25352294843e68193c55b0de4b34a.setOption(option_00a25352294843e68193c55b0de4b34a);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x219df8a4a30>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = (\n",
    "    TreeMap()\n",
    "    .add('', data)\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title='矩形树图'))\n",
    ")\n",
    "c.render_notebook()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
